package eteam.aps.service.impl;


import eteam.aps.common.entity.ParentEntity;
import eteam.aps.common.helper.JsonPage;
import eteam.aps.mapper.DepotMapper;
import eteam.aps.model.entity.Depot;
import eteam.aps.model.vo.DepotVo;
import eteam.aps.service.DepotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 仓库业务层
 *
 * @author WMT
 */
@Service
public class DepotServiceImpl implements DepotService {

    @Autowired
    private DepotMapper depotMapper;

    @Transactional
    @Override
    public int insert(Depot depot) {
        return depotMapper.insert(depot);
    }

    @Transactional
    @Override
    public int delete(String fId){
        return depotMapper.deleteByFId(fId);
    }

    @Transactional
    @Override
    public int update(Depot depot) {
        return depotMapper.updateOne(depot);
    }

    @Override
    public JsonPage<DepotVo> selectAll(Map<String, Object> map, int page, int pageSize) {
        int totalCount = depotMapper.selectAllCount(map);
        List<DepotVo> list = null;
        if (totalCount > 0){
            map.put("offset", (page - 1) * pageSize);
            map.put("limit", pageSize);
            list = depotMapper.selectAll(map);
        }
        return JsonPage.builder(page,pageSize,totalCount,list);
    }

    @Override
    public DepotVo selectDetails(String fId) {
        return depotMapper.selectDetails(fId);
    }

    @Override
    public Depot selectByFId(String fId) {
        return depotMapper.selectByFId(fId);
    }

    @Override
    public int selectFState(String fId) {
        return depotMapper.selectFState(fId);
    }

    @Override
    public List<DepotVo> selectByList() {
        return depotMapper.selectByList(ParentEntity.FSTATE_DELETED);
    }


    @Override
    public int selectCountByDeCode(String deCode) {
        return depotMapper.selectCountByDeCode(deCode);
    }

    @Override
    public int selectCountByDeName(String deName) {
        return depotMapper.selectCountByDeName(deName);
    }
}
